package org.pub.app.util;

import java.util.Comparator;

import org.pub.lunch.mashup.google.Restaurant;

import android.location.Location;

public class SortByCurrentLocation implements Comparator<Restaurant> {

	private Location current;
	
	public SortByCurrentLocation(Location currentLocation) {
		this.current = currentLocation;
	}
	
//	@Override
	public int compare(Restaurant beforeRestaurant, Restaurant afterRestaurnt) {
		if(current == null) {
			return 1;
		} else {
			Location before = beforeRestaurant.getLocation();
			Location after = afterRestaurnt.getLocation();
			float beforeDistance = current.distanceTo(before);
			float afterDistance = current.distanceTo(after);
			return afterDistance > beforeDistance ? -1 : 1; 
		}
	}

}
